# The American Viewer: Political Consequences of Entertainment Media
# Eunji Kim and Shawn Patterson Jr 
# American Political Science Review 
# Replication File [Appendix H Table H1)]



# load data 
appendix_tableh1 <- read.csv("appendix_tableh1_censored.csv")


int1<- felm(romneyshare12_new ~   RTG_8PM_Nov_May + mccainshare08_new+ 
              log(population_04 +1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
              collegeP_04 + foreignBP_04 + unemR_04   + 
              log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x  | 
              STATE  | 0 | 0 , 
            data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 


int2<- felm(mccainshare08_new  ~ RTG_8PM_Nov_May + bushshare04_new + 
              log(population_04+1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04 +
              collegeP_04 + foreignBP_04 + unemR_04   +   
              log(avg_outflow_movers+1) + log(avg_inflow_movers+1)  + pop_density.x      | 
              STATE  | 0 | 0 , data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 



int3<- felm(bushshare04_new  ~ RTG_8PM_Nov_May + bushshare00_new + 
              log(population_04+1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04 +
              collegeP_04 + foreignBP_04 + unemR_04   +   
              log(avg_outflow_movers+1) + log(avg_inflow_movers+1)    + pop_density.x       | 
              STATE  | 0 | 0 , data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 



int4<- felm(gopdiff_12_08  ~ RTG_8PM_Nov_May  + 
              log(population_04+1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04 +
              collegeP_04 + foreignBP_04 + unemR_04   + 
              log(avg_outflow_movers+1) + log(avg_inflow_movers+1)    + pop_density.x       | 
              STATE  | 0 | 0 , data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 

int5<- felm(gopdiff_08_04  ~ RTG_8PM_Nov_May  + 
              log(population_04+1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04 +
              collegeP_04 + foreignBP_04 + unemR_04   +   
              log(avg_outflow_movers+1) + log(avg_inflow_movers+1)    + pop_density.x       | 
              STATE  | 0 | 0 , data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 

int6<- felm(gopdiff_04_00  ~ RTG_8PM_Nov_May  + 
              log(population_04+1) +
              log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04 +
              collegeP_04 + foreignBP_04 + unemR_04   +   
              log(avg_outflow_movers+1) + log(avg_inflow_movers+1)    + pop_density.x       | 
              STATE  | 0 | 0 , data = appendix_tableh1, weights=appendix_tableh1$sum_CNTYTVHH) 


stargazer(int1, int2, int3, int4, int5, int6,  
                                   star.cutoffs = c(0.1, .05,.01,.001),
                                   title="No Correlation Between the Instrument and GOP Support",
                                   dep.var.caption = "",
                                   label = "tab2",
                                   dep.var.labels=c('GOP Share 2012', 'GOP Share 2008', 'GOP Share 2004', 
                                                    'GOP Diff (12-08)', 'GOP Diff (08-04)', 'GOP Diff (04-00)'),
                                   omit.stat=c("adj.rsq","LL","ser","f"),
                                   no.space=TRUE,
                                   omit = 'STATE',
                                   star.char = c("+", "*", "**", "***"), 
                                   notes = c("+ p<0.10; * p<0.05; ** p<0.01; *** p<0.001"), 
                                   notes.append = F,
                                   notes.align="l",
                                   digits=3,
          type="text",
                                   align = TRUE)
